package com.lczyfz.istep.modules.openstack.api.nova.impl;

public class CreateHostImpl {

	/**
	 * TODO���ô��������ع��У���ʱȫ��ע��
	 */

//	private CatalogAndEndpointImpl keystone = CatalogAndEndpointImpl.getInstance();
//	private Endpoint endpoint = keystone.getEndpoint("nova");
//	public List<Host> getHost(){
//		List<Host> host = null;
//		Map<String,String> header = new HashMap<String, String>();
//		header.put("X-Auth-Token", keystone.getToken().getId());
//		header.put("X-Subject-Token", keystone.getToken().getId());
//		Response results = HTTP.getConnectionResult(URL("/os-hosts"), header, null, ConstParams.REQUEST_GET);
//
//		JSONObject body = results.getResponseBody();
//		
//		if(ConstParams.RESPONSE_CODE_NORMAL != results.getResponseCode()){
//			throw new RuntimeException("Failed : HTTP error code : " + results.getResponseCode());
//		}
////		System.out.println(body.toString());
//		host = resolveHosts(body);
//		/**
//		 * TODO����߿�ʼ����body��json��server�Ķ���
//		 */
//		return host;
//	}
//	
//	private List<Host> resolveHosts(JSONObject hostsJson){
//		List<Host> hostList = new ArrayList<Host>();
//		JSONArray hosts = hostsJson.getJSONArray("hosts");
//		for(int i = 0 ; i < hosts.size(); i++){
//			Host host = new Host();
//			host.setHostName( hosts.getJSONObject(i).getString("host_name"));
//			host.setService( hosts.getJSONObject(i).getString("service"));
//			host.setZone( hosts.getJSONObject(i).getString("zone"));
//			hostList.add(host);
//		}
//		return hostList;
//	}
//	
//	public Host hostDetail(){
//		Host host = null;
//		Map<String,String> header = new HashMap<String, String>();
//		header.put("X-Auth-Token", keystone.getToken().getId());
//		header.put("X-Subject-Token", keystone.getToken().getId());
//		Response results = HTTP.getConnectionResult(URL("/os-hosts/openstack-machine"), header, null, ConstParams.REQUEST_GET);
//
//		JSONObject body = results.getResponseBody();
//		
//		if(ConstParams.RESPONSE_CODE_NORMAL != results.getResponseCode()){
//			throw new RuntimeException("Failed : HTTP error code : " + results.getResponseCode());
//		}
////		System.out.println(body.toString());
//		host = resolveHost(body);
//		/**
//		 * TODO����߿�ʼ����body��json��server�Ķ���
//		 */
//		return host;
//	}
//	
//	private Host resolveHost(JSONObject hostsJson){
//		Host host = new Host();
//		JSONArray hostresoures = hostsJson.getJSONArray("host");
//		for(int i = 0 ; i < hostresoures.size(); i++){
//			Host_resource host_resource = new Host_resource();
//			host_resource.setCpu( hostresoures.getJSONObject(i).getJSONObject("resource").getString("cpu"));
//			host_resource.setDisk( hostresoures.getJSONObject(i).getJSONObject("resource").getString("disk_gb"));
//			host_resource.setHost( hostresoures.getJSONObject(i).getJSONObject("resource").getString("host"));
//			host_resource.setMemory( hostresoures.getJSONObject(i).getJSONObject("resource").getString("memory_mb"));
//			host_resource.setProject( hostresoures.getJSONObject(i).getJSONObject("resource").getString("project"));
//			host.ListAdd(host_resource);
//		}
//		return host;
//	}
//	
//	private String URL(String url){
//		return this.endpoint.getUrl() + url;
//	}
//	
//	public Host hostReboot(){
//		Host host = null;
//		Map<String,String> header = new HashMap<String, String>();
//		header.put("X-Auth-Token", keystone.getToken().getId());
//		header.put("X-Subject-Token", keystone.getToken().getId());
//		Response results = HTTP.getConnectionResult(URL("/os-hosts/openstack-machine/reboot"), header, null, ConstParams.REQUEST_GET);
//
//		JSONObject body = results.getResponseBody();
//		
//		if(ConstParams.RESPONSE_CODE_NORMAL != results.getResponseCode()){
//			throw new RuntimeException("Failed : HTTP error code : " + results.getResponseCode());
//		}
////		System.out.println(body.toString());
//		host = resolveHostAction(body);
//		/**
//		 * TODO����߿�ʼ����body��json��server�Ķ���
//		 */
//		return host;
//	}
//	
//	public Host hostStart(){
//		Host host = null;
//		Map<String,String> header = new HashMap<String, String>();
//		header.put("X-Auth-Token", keystone.getToken().getId());
//		header.put("X-Subject-Token", keystone.getToken().getId());
//		Response results = HTTP.getConnectionResult(URL("/os-hosts/openstack-machine/startup"), header, null, ConstParams.REQUEST_GET);
//
//		JSONObject body = results.getResponseBody();
//		
//		if(ConstParams.RESPONSE_CODE_NORMAL != results.getResponseCode()){
//			throw new RuntimeException("Failed : HTTP error code : " + results.getResponseCode());
//		}
////		System.out.println(body.toString());
//		host = resolveHostAction(body);
//		/**
//		 * TODO����߿�ʼ����body��json��server�Ķ���
//		 */
//		return host;
//	}
//	
//	public Host hostShutdown(){
//		Host host = null;
//		Map<String,String> header = new HashMap<String, String>();
//		header.put("X-Auth-Token", keystone.getToken().getId());
//		header.put("X-Subject-Token", keystone.getToken().getId());
//		Response results = HTTP.getConnectionResult(URL("/os-hosts/openstack-machine/shutdown"), header, null, ConstParams.REQUEST_GET);
//
//		JSONObject body = results.getResponseBody();
//		
//		if(ConstParams.RESPONSE_CODE_NORMAL != results.getResponseCode()){
//			throw new RuntimeException("Failed : HTTP error code : " + results.getResponseCode());
//		}
////		System.out.println(body.toString());
//		host = resolveHostAction(body);
//		/**
//		 * TODO����߿�ʼ����body��json��server�Ķ���
//		 */
//		return host;
//	}
//	
//	private Host resolveHostAction(JSONObject hostsJson){
//		Host host = new Host();
//		host.setHostName(hostsJson.getString("host"));
//		host.setPowerAction(hostsJson.getString("power_action"));
//		return host;
//	}
//	
//	public void hostUpdatestatus(){
//		
//	}
//	public static void main(String[] args){
////		Keystone keystone = Keystone.getInstance();
////		
////		System.out.println(keystone.getEndpoints().get("keystone").getUrl());
////		System.out.println(Identity.getInstance().login().getId());
//		CreateHost Host = new CreateHost();
//		
//		List<Host> hosts = Host.getHost();
//		Host hostresources = Host.hostDetail();
//		System.out.println("�����б�����");
//		for(Host host : hosts){
//			System.out.println(host.getHostName()+" "+host.getService()+" "+host.getZone());
//		}
//		System.out.println("������ϸ�б�");
//		for(Host_resource hostresource : hostresources.getHostresource()){
//			System.out.println(hostresource.getCpu()+" "+hostresource.getDisk()+" "+hostresource.getHost()+" "+hostresource.getMemory()+" "+hostresource.getProject());
//		}
//	}
}
